<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      table,
      tr,
      td {
        border: 1px solid blue;
        border-collapse: collapse;
      }
      table {
        width: 60%;
        margin: 40px auto;
      }
      h3 {
        text-align: center;
      }
    </style>
  </head>
  <body>
    <!-- 1. 先准备一个容器 -->
    <div id="app">
      <h3>水果店</h3>
      <table>
        <tr>
          <td>苹果{{price}}斤 折扣{{discount}}折</td>
        </tr>
        <tr>
          <td>斤数 <input type="text" v-model="num" /></td>
        </tr>
        <tr>
          <td><button @click="fn">结账买单</button></td>
        </tr>
        <tr>
          <td>账单 总价 {{total}}元 折后{{discountTotal}} 省了 {{youhui}}元</td>
        </tr>
      </table>
      <hr />
      <!-- 一组复选框：每个复选框要有value值，并且它们的v-model是一样的 -->
      <label v-for="(item,index) in list" :key="index">
        <input type="checkbox" v-bind:value="item" v-model="selectedList" />
        {{item}}
      </label>
      <ul>
        <li v-for="(item,index) in selectedList" :key="index">{{item}}</li>
      </ul>
    </div>
    <!-- 2. 引框架 -->
    <script src="./vue.js"></script>
    <script>
      // 3.初始化vue实例对象
      const vm = new Vue({
        el: "#app",
        data: {
          price: 10,
          discount: 8,
          num: 2,
          total: 0,
          discountTotal: 0,
          youhui: 0,
          //有id用id 无id用下标
          list: [
            "科幻",
            "喜剧",
            "动漫",
            "冒险",
            "科技",
            "军事",
            "娱乐",
            "奇闻",
          ],
          selectedList: [],
        },
        methods: {
          fn() {
            this.total = this.price * this.num;
            this.discountTotal = (this.total * this.discount) / 10;
            this.youhui = this.total - this.discountTotal;
          },
        },
      });
    </script>
  </body>
</html>
